package com.example.demo.controller;

import com.example.demo.dto.AttributeListRequestDTO;
import com.example.demo.dto.AttributeLogRequestDTO;
import com.example.demo.controller.bean.Result;
import com.example.demo.mapper.entity.*;
import com.example.demo.service.AttributeManageService;
import com.example.demo.utils.PageBo;
import com.example.demo.utils.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("attributeManage")
@Api(value = "属性管理接口", tags = {"属性管理接口"})
@RestController
@Slf4j
public class AttributeManageController {
    @Autowired
    private AttributeManageService service;

    //属性列表
    @ResponseBody
    @ApiOperation(value = "获取屬性列表接口")
    @RequestMapping(value = "getAttributeList", method = {RequestMethod.POST})
    public Result<PageVo<Attribute>> getList(@RequestBody PageBo pageBo) {
        PageVo<Attribute> list = service.getAttributeList(pageBo);
        return Result.ok(list);
    }

    @ResponseBody
    @ApiOperation(value = "搜索列表接口")
    @RequestMapping(value = "searchAttributeList", method = {RequestMethod.POST})
    public Result<PageVo<Attribute>> getListSearch(@RequestBody AttributeListRequestDTO request) {
        String name=request.getName();

        PageBo pageBo = new PageBo();
        pageBo.setPageNum(request.getPageNum());
        pageBo.setPageSize(request.getPageSize());

        PageVo<Attribute> logs = service.searchAttributeList(name,pageBo);
        return Result.ok(logs);
    }

    @ResponseBody
    @RequestMapping(value = "addAttributeList", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation("屬性新增接口")
    public Result<String> addUser(@RequestBody AttributeListRequestDTO request) {
        return service.addAttribute(request);
    }

    @ResponseBody
    @ApiOperation("删除屬性接口")
    @RequestMapping(value = "deleteAttributeList", method = {RequestMethod.POST})
    public Result<String> delete(@RequestBody Attribute attribute) {
        return service.deleteAttributeList(attribute);
    }

    @ResponseBody
    @ApiOperation("批量删除接口")
    @RequestMapping(value ="batchDeleteAttributeList", method = {RequestMethod.POST})
    public Result<String> deleteList(@RequestBody List<Attribute> attributeList) {
        service.batchDeleteAttributeList(attributeList);
        return Result.ok("删除成功");
    }

    @ResponseBody
    @ApiOperation("修改屬性接口")
    @RequestMapping(value = "updateAttributeList", method = {RequestMethod.POST})
    public Result<String> updateAttributeList(@RequestBody AttributeListRequestDTO request) {
        return service.updateAttributeList(request);
    }

    //属性日志
    @ResponseBody
    @ApiOperation(value = "获取属性日志接口")
    @RequestMapping(value = "getAttributeLog", method = {RequestMethod.POST})
    public Result<PageVo<StudentAttributeView>> getAttributeLog(@RequestBody PageBo pageBo) {
        PageVo<StudentAttributeView> list = service.getAttributeLog(pageBo);
        return Result.ok(list);
    }

    @ResponseBody
    @ApiOperation(value = "搜索日志接口")
    @RequestMapping(value = "searchAttributeLog", method = {RequestMethod.POST})
    public Result<PageVo<StudentAttributeView>> getListSearch(@RequestBody AttributeLogRequestDTO request) {
        PageBo pageBo = new PageBo();
        pageBo.setPageNum(request.getPageNum());
        pageBo.setPageSize(request.getPageSize());

        PageVo<StudentAttributeView> logs = service.searchAttributeLog(request,pageBo);
        return Result.ok(logs);
    }


    @ResponseBody
    @ApiOperation("修改屬性接口")
    @RequestMapping(value = "updateAttributeLog", method = {RequestMethod.POST})
    public Result<String> updateAttributeLog(@RequestBody AttributeLogRequestDTO request) {
        return service.updateAttributeLog(request);
    }

}
